/**
	Copyright (c) 2009 ATTi 
	All rights reserved.
	Author: Michael Shu
	Date: 12/28/2009
*/
@isTest
private class SelectCaseAttachmentControllerTester {
	private static Case curCase;
	private static SelectCaseAttachmentController controller;
	private static List<Attachment> caseAtts;
	private static PageReference nextPage;
	
	private static void testInit() {
		String csSubject = '--testSubjectonly--';
		String csWebEmail = 'email@testsandbox.com';
		String csDescription = 'This is for test only';
		Case newCase = new Case(subject = csSubject, SuppliedEmail = csWebEmail, description = csDescription);
		insert newCase;
		
		curCase = [select Id from Case where subject =: csSubject and SuppliedEmail =: csWebEmail limit 1];	
		
		List<Attachment> newCaseAtts = new List<Attachment>();
		String attName = 'TestCaseAttachment_';
		for(Integer i = 0; i < 10 ; i++ ){
			Attachment a = new Attachment(Name = attName + i, ParentId = curCase.Id, Body = Blob.valueOf('This is a Test' + i));
			newCaseAtts.add(a);
		}
		insert newCaseAtts;	
		caseAtts =[select Id, Name from Attachment where ParentId =: curCase.Id];      	
		System.assertEquals(10, caseAtts.size());
	}	
	
	public static testMethod void testSelectAttachment(){
		testInit();
		PageReference pageRef = Page.SelectCaseAttachmentPage;
		Test.setCurrentPage(pageRef);
		
		controller = new SelectCaseAttachmentController();
		System.assertEquals(true, controller.lattachment.isEmpty());
		
		ApexPages.currentPage().getParameters().put('caseId', curCase.Id);	
		controller = new SelectCaseAttachmentController();
		System.assertEquals(10, controller.lattachment.size());

		System.assertEquals('', controller.selectedIdString);
				
		nextPage = controller.selectAll();
		
		for(Attachment a : caseAtts){
			String idStr = a.Id;
			System.assertEquals(true, controller.selectedIdString.contains(idStr));
		}
		
		nextPage = controller.selectAll();
		System.assertEquals('', controller.selectedIdString);
	}
}